<?php include "./pc/view/header.inc.htm"; ?>

<div class="panel">
	<div class="header">重设密码</div>
	<div class="body">
		<div style="width: 300px; margin: auto;">
			<form method="POST" id="form" action="user-resetpw.htm" class="form">
				<p><?php echo $_user['email']; ?></p>
				<p><input type="password" placeholder="新密码" name="password" style="width: 100%;"></p>
				<p><input type="password" placeholder="重复密码" name="password2" style="width: 100%;"></p>
				<dl class="row margin">
					<dt><button type="submit" loading-text="正在登录..." class="blue big" style="width: 100px;">重设密码</button></dt>
				</dl>			
			</form>
		</div>
	</div>
</div>

<?php include "./pc/view/footer.inc.htm"; ?>

<script>

$(function() {
	var jform = $('#form');
	var jsubmit = jform.find('button[type="submit"]');
	var jpassword = jform.find('input[name="password"]');
	var jpassword2 = jform.find('input[name="password2"]');
	jform.off('submit').on('submit', function() {
	//jsubmit.off('click').on('click', function() {
		if(!jpassword.val()) {
			jpassword.popover('请输入密码').focus();
			return false;
		}
		if(jpassword.val() != jpassword2.val()) {
			jpassword2.popover('两次输入的密码不一致').focus();
			return false;
		}
		var postdata = {password: $.md5(jpassword.val())};
		jsubmit.button('loading');
		$.xpost(jform.attr('action'), postdata, function(code, message) {
			if(code == 0) {
				$.alert('重设密码成功，请重新登录');
				setTimeout(function() {jsubmit.button('reset'); window.location='user-login.htm';}, 2000);
			} else if(code == 1) {
				jpassword.popover(message).focus();
				jsubmit.button('reset');
			} else {
				$.alert(message);
				setTimeout(function() {jsubmit.button('reset');}, 1000);
			}
		});
		return false;
	});
});
</script>